package dl.bukkit.myststus.api.listener;

import dl.bukkit.myststus.MyStatus;
import dl.bukkit.myststus.library.container.ListContainer;
import dl.bukkit.myststus.loader.Loader;
import org.bukkit.Bukkit;

import java.util.LinkedList;

public class ListenerManager implements Loader {

    private final MyStatus plugin;
    private final ListContainer<IListener> container;

    public ListenerManager(MyStatus plugin) {
       this.plugin = plugin;
       this.container = new ListContainer<>(new LinkedList<>(), MyStatus.class);
    }

    @Override
    public void onLoad() {
        this.container.register(HealthListener.class, plugin);
        this.container.register(PlayerListener.class, plugin);
    }

    @Override
    public void staring() {
        container.getList().stream().filter(IListener::isRegister).forEach(listener -> Bukkit.getPluginManager().registerEvents(listener, plugin));
    }
}
